const ioioi = require('../main');

function context() {
  return {
    exec : null,
    method : '',
    pass : ''
  };
}

let ioi = new ioioi.mgroup({
  debug:true,
  cache: true
});

let postCheck = (c) => {
  console.log('post check...')
  if (c.method == 'POST' && c.pass !== 'abc') {
    console.log('  post deny');
    return false;
  }
  return true;
};

let m1 = async (c, next) => {
  console.log('m1 in');
  await next();
  console.log('m1 out');
};

ioi.use(m1, 'test');

ioi.use(async (c, next) => {
  console.log('m2 in');
  await next();
  console.log('m2 out');
}, postCheck, 'test');

ioi.use(async (c, next) => {
  console.log('m3 in');
  await next();
  console.log('m3 out');
});

let b = context();

b.method = 'POST';
b.pass = 'abcd';
b.exec = async (c) => {
  console.log('  I am b');
};

console.log(ioi)

ioi._loadstack()

console.log(ioi)

;(async () => {
  await ioi.run(b);

  console.log('----');
  
  await ioi.run(b, 'test');

})();

